#include "StdAfx.h"
#include "StrUtil.h"


template<typename T>
vector<T> split(const T & str, const T & delimiters, bool ignoreEmpty) 
{
    vector<T> v;
    typename T::size_type start = 0;
    int pos = str.find_first_of(delimiters, start);
    while(pos != T::npos) 
	{
        if(pos != start) // ignore empty tokens
		{
            v.push_back(str.substr(start, pos - start));
		}
        start = pos + 1;
        pos = str.find_first_of(delimiters, start);
    }

	if (ignoreEmpty )
	{
		if(start < str.length()) // ignore trailing delimiter
		{
			v.push_back(str.substr(start)); // add what's left of the string
		}
	}

    return v;
}


CStrUtil::CStrUtil(void)
{
}


CStrUtil::~CStrUtil(void)
{
}

vector<string> CStrUtil::Split(const string & str, const string & delimiters, bool ignoreEmpty)
{
	return split<string>(str, delimiters, ignoreEmpty);
}